﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Ample.Model;

namespace Ample.BLL.Store
{
    [System.ComponentModel.DataObject]
    public class OrderItemBO
    {
        #region Get Methods

        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, true)]
        public IEnumerable<OrderItem> GetOrderItems()
        {
            return DAL.OrderItemManager.Create().GetOrderItems();
        }

        //[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        //public Order GetOrderById(int orderId)
        //{
        //    return DAL.OrderItemManager.Create().GetOrderById(orderId);
        //}

        //[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        //public IEnumerable<Order> GetOrderByTypeId(int prodTypeId)
        //{
        //    if (prodTypeId < 0)
        //        return GetOrderItems();
        //    else
        //        return DAL.OrderItemManager.Create().GetOrderByTypeId(prodTypeId);
        //}

        #endregion


        #region Insert Methods

        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public int InsertOrder(OrderItem orderItem)
        {
            ApplyRules(orderItem);
            OperationStatus opStatus = DAL.OrderItemManager.Create().InsertOrderItem(orderItem);
            if (!opStatus.Status)
            {
                throw new ApplicationException(String.Format("Error occurred in BLL.OrderRules.InsertOrder: {0}", opStatus.Exception.Message));
            }

            return opStatus.InsertedRowID;
        }

        #endregion


        #region Update Methods

        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, true)]
        public void UpdateOrder(OrderItem orderItem)
        {
            ApplyRules(orderItem);
            OperationStatus opStatus = DAL.OrderItemManager.Create().UpdateOrderItem(orderItem);
            if (!opStatus.Status)
            {
                throw new ApplicationException(String.Format("Error occurred in BLL.OrderRules.UpdateOrder: {0}", opStatus.Exception.Message));
            }
        }

        #endregion


        #region Delete Methods

        public static void DeleteOrder(OrderItem orderItem)
        {
            OperationStatus opStatus = DAL.OrderItemManager.Create().DeleteOrderItem(orderItem);
            if (!opStatus.Status)
            {
                throw new ApplicationException(String.Format("Error occurred in BLL.OrderRules.DeleteOrder: {0}", opStatus.Exception.Message));
            }
        }

        #endregion

        #region Business Rules

        private static void ApplyRules(OrderItem orderItem)
        {

        }

        #endregion

    }
}
